<template>
	<view>
		<u-navbar
			title="申请退款"
			:autoBack="true"
			placeholder
		>
		</u-navbar>
		<scroll-view :scroll-y="true" :style="{height: scrollViewHeight}">
			<template v-if="loading">
				<view style="padding: 32rpx;">
					<u-skeleton style="margin-bottom: 32rpx;" :loading="loading" avatar rows="7" v-for="i in 8" :key="i"></u-skeleton>
				</view>
			</template>
			<template v-else>
				<view style="height: 16rpx;"/>
				<view class="logistics-box">
					<view class="logistics-title">
						<text class="logistics-title-l">订单编号:</text>
						<text class="logistics-title-r">{{detail.id}}</text>
					</view>
					<view class="logistics-title">
						<text class="logistics-title-l">门票名称:</text>
						<text class="logistics-title-r">{{detail.ticketName}}x{{detail.buyCount}}</text>
					</view>
					<view class="logistics-title">
						<text class="logistics-title-l">游玩日期:</text>
						<text class="logistics-title-r">{{detail.ticketTime}}</text>
					</view>
					<view class="logistics-title">
						<text class="logistics-title-l">下单时间:</text>
						<text class="logistics-title-r">{{detail.createTime}}</text>
					</view>
					<view class="logistics-title" style="margin-bottom: 0;">
						<text class="logistics-title-l">支付方式:</text>
						<text class="logistics-title-r">{{detail.payMethod_dictText}}</text>
					</view>
				</view>
				<view style="height: 16rpx;"/>
				<u--form labelPosition="left" :model="model" ref="form1">
					<view style="padding: 0 32rpx;background-color: #fff;">
						<u-form-item @click="showReason = true" labelWidth="80" label="退款原因" borderBottom ref="refundReason">
							<u--input disabled disabledColor="#ffffff" placeholder="请选择退款原因" v-model="model.refund.refundReason" border="none"></u--input>
							<u-icon slot="right" name="arrow-right"></u-icon>
						</u-form-item>
						<u-form-item labelWidth="80" label="退款金额" borderBottom ref="refundPrice">
							<text :style="{color: appColor}">&yen;{{detail.payPrice | moneyFormat}}</text>
							<!-- <u--input placeholder="请选择处理方式" v-model="refundPrice" border="none"></u--input> -->
						</u-form-item>
						<u-form-item labelWidth="80" label="备注信息" :borderBottom="false" ref="remark">
							<u--input placeholder="请输入备注信息" v-model="model.refund.remark" border="none"></u--input>
						</u-form-item>
					</view>
				</u--form>
			</template>
		</scroll-view>
		<view class="good-detail-bootom" v-if="!loading">
			<view style="margin: 0 32rpx;height: 100%;width: calc(100vw - 64rpx);display: flex;align-items: center;justify-content: space-between;">
				<view class="good-detail-bootom-r">
					<u-button @click="submit" :color="appColor" text="提交" shape="circle"></u-button>
				</view>
			</view>	
		</view>
		<u-action-sheet
				:show="showReason"
				:actions="actions"
				title="请选择退款原因"
				@close="showReason = false"
				@select="refundReasonSelect"
		>
		</u-action-sheet>
	</view>
</template>

<script>
	import {mapState, mapActions} from 'vuex';
	import {ticketQueryById, parkTicketAfterOrder} from '@/api/me.js';
	import {getDictItems} from '@/api/me.js';
	export default {
		data() {
			return {
				loading: true,
				actions: [],
				showReason: false,
				model: {
					refund: {
						refundReason: undefined,
						phone: undefined,
						remark: '',
					},
				},
				detail: {},
				orderId: undefined
			}
		},
		computed: {
			...mapState(['appInfo']),
			appColor() {
				return this.appPrimaryColor
			},
			scrollViewHeight() {
				return this.scrollHeight - 44 - 50 + 'px';
			},
		},
		onLoad({id}) {
			this.orderId = id;
			this.loading = true;
			ticketQueryById({id}).then(res => {
				this.detail = res.result;
			}).finally(() => {
				this.loading = false;
			})
			getDictItems('ticket_refund').then(res => {
				this.actions = res.result
			})
		},
		methods: {
			refundReasonSelect(e) {
				this.model.refund.refundReason = e.name;
			},
			// 提交
			submit() {
				let {refundReason, remark} = this.model.refund;
				remark = uni.$u.trim(remark);
				if(!refundReason) {
					return this.$cuTip('请选择退款原因');
				}
				let refundReasonVal = this.actions.find(item => item.name === refundReason).value
				if(!remark) {
					return this.$cuTip('请输入备注信息');
				}
				let postObj = {
					orderId: this.orderId,
					refundReason: refundReasonVal,
					remark,
				};
				this.$cuLoading().then(() => {
					parkTicketAfterOrder(postObj).then(res => {
						uni.hideLoading();
						this.$cuTip('提交成功').then(() => {
							uni.navigateBack({
								delta: 1
							})
						});
					}).catch(() => {
						uni.hideLoading();
					})
				})
			},
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}
</style>

<style lang="scss" scoped>
	.shop-cart-box {
		background-color: #fff;
		padding: 32rpx;
		display: flex;
		align-items: center;
		.shop-cart-l {
			display: flex;
			align-items: center;
			width: 72rpx;
		}
		.shop-cart-r {
			flex: 1;
			display: flex;
			.shop-cart-r-1 {
				flex: 1;
				.shop-cart-r-1-title {
					line-height: 34rpx;
					font-size: 28rpx;
					color: #000;
					height: 68rpx;
				}
				.shop-cart-r-1-con {
					height: 48rpx;
					display: flex;
					justify-content: space-between;
					align-items: center;
				}
			}
		}
	}
	
	.logistics-box {
		padding: 32rpx;
		background-color: #fff;
		.logistics-title {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			line-height: 28rpx;
			margin-bottom: 32rpx;
			.logistics-title-l {
				color: #666;
				padding-right: 8rpx;
			}
			.logistics-title-r {
				color: #333;
			}
		}
	}
	
	
	.good-detail-bootom {
		background-color: #ffffff;
		position: fixed;
		height: 50px;
		width: 100vw;
		bottom: 0;
		left: 0;
		padding-bottom: constant(safe-area-inset-bottom);     /*兼容 iOS<11.2*/
		padding-bottom: env(safe-area-inset-bottom);  /*兼容 iOS>11.2*/
		box-sizing: content-box;
		.good-detail-bootom-l1 {
			display: flex;
			flex-direction: column;
			justify-content: center;
			.good-detail-bootom-l1-t {
				font-size: 28rpx;
				padding-bottom: 4rpx;
			}
			.good-detail-bootom-l1-b {
				.good-detail-bootom-l1-b-1 {
					display: flex;
					align-items: center;
					font-size: 24rpx;
				}
			}
		}
		.good-detail-bootom-r {
			flex: 1;
		}
	}
</style>